﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using Cn.Edwon.Biz;
using Cn.Edwon.Spring;
using Cn.Cellula.Model.System;
using Cn.Cellula.Client.ControlHelper;
using Cn.Cellula.Biz.Port;
using System.Collections.Generic;
using Cn.Edwon.Web;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Db.Dm {
    public partial class Table : PageSupport {
        IDbBiz biz = BizFactory.Get<IDbBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                this.LoadTables();
            }
        }

        private void LoadTables() {
            this.gvList.DataSource = biz.LoadAll<TSysTableEO>();
            this.gvList.DataBind();
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e) {
            this.gvList.PageIndex = e.NewPageIndex;
            this.LoadTables();
        }

        public Int32 GetTableRowCount(Object rEOName) {
            try {
                IList<Object> list = biz.Find("from "+rEOName.ToString(),-1);
                Int32 count =  (list != null && list.Count > 0) ? list.Count : 0;
                list = null;
                return count;
            } catch {
                return -1;
            }
        }

        protected void btn_Clear_Click(object sender, EventArgs e) {
            IList<String> keys = GvHelper.GetSelectedKey(ref this.gvList, ClientBiz.GRIDVIEW_ROW_CHECKBOX_ID);
            if (keys != null && keys.Count > 0) {
                biz.ClearTableData(keys);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoMultiSelect);
                return;
            }
        }
        
    }
}
